package com.cxb.service;

import com.cxb.view.FloatingView;

import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

public class FloatService extends Service {  
	FloatingView view ;
	public static final String STOPHOMEKEY = "android.intent.action.STOPHOMEKEY";
	public static final String SHOWHOMEKEY = "android.intent.action.SHOWHOMEKEY";
	private HomeKeyStopReceiver receiver;
    //����  
	//Ϊ����activity���button�� �ڿ���һ��service   
      
    @Override  
    public IBinder onBind(Intent intent) {  
        return null;  
    }  
  
    public void onCreate() {  
    	super.onCreate();  
       
    }  
  
    @Override  
    public int onStartCommand(Intent intent, int flags, int startId) {  
    	view = new FloatingView(this);  
    	view.showFloatingBtn();
    	 
        /**2015-06-08 添加一个广播监听Home键 是否要显示**/
    	receiver = new HomeKeyStopReceiver();
    	IntentFilter filter = new IntentFilter();
		filter.addAction(STOPHOMEKEY);
		filter.addAction(SHOWHOMEKEY);
		registerReceiver(receiver, filter);
        return super.onStartCommand(intent, flags, startId);  
    }  
    
    /**2015-06-08 监听Home键广播 **/
	class HomeKeyStopReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			String msg = intent.getAction();
			if (msg.equals(STOPHOMEKEY)) {
				view.removeView();
			}
			
			if (msg.equals(SHOWHOMEKEY)) {
				view.ShowView();
			}
		}

	}
}  